/**
 * 用户详情对话框
 */
var UserInfoDlg = {
    data: {
        deptId: "",
        deptName: ""
    }
};

layui.use(['layer', 'form', 'admin', 'laydate', 'ax','layarea'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var laydate = layui.laydate;
    var layer = layui.layer;
    var layarea = layui.layarea;

    let num = 1;
    $('#btn').click(function () {
        num ++;
        var content =
            `<div class="layui-form-item" style="margin-left: 114px;">
                <div class="layui-input-inline" style="margin-top: 10px">
                    <input name="placeClass${num}" placeholder="请输入班级号" type="text" class="layui-input" />
                    <input name="num${num}" placeholder="请输入班级座位总数" type="text" class="layui-input"/>
                </div>
                <button type="button" class="layui-btn layui-btn-sm"  style="margin: 10px 0 0 10px" id="remove">
                    <i class="layui-icon">&#xe640;</i>
                </button>
            </div>`;
        $("#content").append(content);
    });
    $('#content').on('click',' #remove',function () {
        $(this).parent().remove();
    })

    // 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        let arr = [];
        for(let k in data.field) {
            if(data.field.hasOwnProperty(k)) {
                if(k.includes('placeClass')) {
                    let n = k.substr(10);
                    let placeClassNum = 'num' + n;
                    arr.push({placeClass: data.field[k],placeClassNum: data.field[placeClassNum]})
                }
            }
        }
        data.field.placeClass = JSON.stringify(arr);
        var ajax = new $ax(Feng.ctxPath + "/exam/examPlaceSave", function (data) {
            Feng.success("添加成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();
    });
});